<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<jsp:include page="../common/common.jsp">
	<jsp:param name="title" value="组群"/>
</jsp:include>

<div class="page-header">
	<h1>
		组群列表
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			添加${groupname}组员
		</small>
	</h1>
</div>

<div class="row">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div>
					<div class="dataTables_wrapper form-inline no-footer">
						<table id="_table" class="table table-striped table-bordered table-hover dataTable no-footer">
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- page specific plugin scripts -->
<script type="text/javascript">
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		jQuery(function($) {
			var gid='${gid}';
		// 列表(jquery.table.min.js中定义了table)
    		var $table = $("#_table").table({
    			//请求后台的URL（*）
    			url : "${_path}/admin/group/addmember/list",
    			data:{gid:gid},
				tools : [
					{text : '添加至组', clazz : 'btn-success', icon : 'fa fa-user-plus green', permission : '/admin/group/addmember/submit', handler : function(){
						$table.ajaxEnable(
								{
									url : "${_path}/admin/group/addmember/submit",
								    data : {gid:gid},
								    after : function(){
								    	window.location.href="${_path}/admin/admin#/admin/group/list/page?id="+gid;
								    }
								}, 
								true
						);
					}}
				],
				//表格的列
				columns : [
			        {field:'id'},
			        {field:'isEnable', hide : true},
			        {field:'account', title:'组员名', align:'left'},
			        {field:'loginCount', title:'登录总次数', hide : true},
			        {field:'lastLoginIp', title:'最后登录IP', mobileHide : true},
			        {field:'lastLoginTime', title:'最后登录时间', hide : true},
			        {field:'isEnableStr', title:'是否启用', replace : function (d){
				        if(d.isEnable)
				        	return "<span class='label label-sm label-success'>" + d.isEnableStr + 	"</span>";
			        	else
			        		return "<span class='label label-sm label-warning'>" + d.isEnableStr + "</span>";
			        }},
			        {field:'createTime', title:'创建时间', hide : true}
				],
				operate : [],
				after : function(){
					// 权限处理
					$.permission();
				}
			});
		
    		//初始化表格复选框
    		var members=eval('${members}');
    	   for(var i=0;i<members.length;i++){
    			$("#_table > tbody > tr").each(
    					function(){
    						var trId=$(this).find("td:nth-child(2)").text();	
    						if(parseInt(trId)==members[i]){
    							//$(this).find("td input[type=checkbox]").prop('checked', true);
    							$(this).find("td input[type=checkbox]").prop('disabled', "disabled");
    						} 
    					}
    			);
    		} 
    		$("#_table tr").find("td:nth-child(2),th:nth-child(2)").css("display","none");
    		
			//搜索
			$(".search-data").keyup(function () { 
				$table.search();
			});
            
			// 取消
			$("#_cancel").click(function(){
				$table.search();
			}); 
		});
	});
</script>
